package com.shadt.cloud.apis;

import java.text.ParseException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.shadt.core.controller.BaseController;
import com.shadt.core.model.Json;
import com.shadt.core.util.DateUtil;
import com.shadt.core.util.HttpClientUtil;
import com.shadt.core.util.MD5Util;

/**
 * 测试类
 * @author SongR
 *
 */
@Controller
@RequestMapping(value="/dev")
public class DevController extends BaseController{
	
	/**
	 * app名称
	 */
	final String APP_NAME="SongR";
	/**
	 * 安全码
	 */
	final String SECURITY="lPnkj7bvCRfbxJyccqjnn3gLAWOs5Ejc";
	final String PARAM="[{'key':'CLOUD1000HOMENEWS','start':1,'size':10},{'key':'CLOUD1000INTERNATIONALNEWS','start':1,'size':10},{'key':'CLOUD1000SPORTS','start':1,'size':10},{'key':'CLOUD1000ENTERTAINMENT','start':1,'size':10},{'key':'CLOUD1000ECNOMICS','start':1,'size':10},{'key':'CLOUD1000SCIENCEANDTECHNOLOGY','start':1,'size':10},{'key':'CLOUD1000MILITARY','start':1,'size':10},{'key':'CLOUD1000SOCIOLOGY','start':1,'size':10},{'key':'ZJLYZQDL','start':1,'size':10}]";
	@ResponseBody
	@RequestMapping(value="/test")
	public String recordTest(String ip) throws ParseException{
		String time  = DateUtil.dateToStamp(DateUtil.dataToStr(new Date(), "yyyy-MM-dd HH:mm:ss"));
		String sign = MD5Util.md5("appname="+APP_NAME+"param="+PARAM+"time="+time+SECURITY);
		Map<String,String> map = new HashMap<String,String>();
		map.put("appname", APP_NAME);
		map.put("param", PARAM);
		map.put("time", time);
		map.put("sign", sign);
		String s = new HttpClientUtil().doPost("http://"+ip+"/qczlcloud/api/v2.0/record/get", map);
		System.out.println(s);
		return s;
	}
	
	
	
	
	@ResponseBody
	@RequestMapping(value="/test1")
	public Json test(){
		Json j = new Json();
		try {
			new HttpClientUtil().doPost1("http://192.168.2.62/qczlcloud/api/record/get?f=v2.0", null);
		} catch (Exception e) {
			e.printStackTrace();
		}
		System.out.println(1);
		j.setObj(1);
		return j;
	}
 
}
